package opeartion;

import book.Book;
import book.BookList;

import java.util.Scanner;

public class DelOperation implements IOPeration{
    @Override
    public void work(BookList bookList) {
        System.out.println("删除图书");
        Scanner in=new Scanner(System.in);
        System.out.println("请输入需要删除的图书：");
        String name=in.nextLine();
        int size=bookList.getUsedSize(),i=-1,j;
        for (j = 0; j < size; j++) {
            Book book=bookList.getBooks(j);
            if(book.getName().equals(name)){
                i=j;
                break;
            }
        }
        if(i!=-1){
            for (j = i; j < size-1; j++) {
                Book book2=bookList.getBooks(j+1);
                bookList.setBooks(j,book2);
            }
            bookList.setUsedSize(size-1);
            System.out.println("删除成功！");
            return;
        }
        System.out.println("删除失败！");
    }
}
